let base_url = 'http://120.55.194.140:8080/funong'
let $request = function(url, data = {}, method = "GET") {
	return uni.request({
		url: url,
		data,
		method,
		header:{
			Authorization:uni.getStorageSync("token")
		}
	}).then(res => {
		return res.data
	})
}
async function login(username, password) {
	const raw = {
		username: username,
		password: password
	}
	const data = await $request(base_url + "/login", raw, "POST").catch(err => {
		console.error(err)
	})
	uni.setStorageSync("token",data.token)
}
uni.$login = login
uni.$base_url = base_url
uni.$request = $request
uni.$get = function(url, data = {}) {
	return $request(base_url + url, data).catch(err => {
		console.error(err)
	})
}
uni.$post = function(url, data = {}) {
	return $request(base_url + url, data, "POST").catch(err => {
		console.error(err)
	})
}
uni.$put = function(url, data = {}) {
	return $request(base_url + url, data, "PUT").catch(err => {
		console.error(err)
	})
}
uni.$delete = function(url, data = {}) {
	return $request(base_url + url, data, "DELETE").catch(err => {
		console.error(err)
	})
}